from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-13 14:02:52.147028
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 13, Jun, 2022
Time: 14:02:59
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5414
Nobs: 686.000 HQIC: -49.9059
Log likelihood: 8526.08 FPE: 1.68374e-22
AIC: -50.1359 Det(Omega_mle): 1.47812e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.307948 0.058830 5.235 0.000
L1.Burgenland 0.104457 0.038214 2.733 0.006
L1.Kärnten -0.109045 0.020166 -5.407 0.000
L1.Niederösterreich 0.201587 0.079808 2.526 0.012
L1.Oberösterreich 0.116319 0.078261 1.486 0.137
L1.Salzburg 0.256107 0.040786 6.279 0.000
L1.Steiermark 0.045097 0.053379 0.845 0.398
L1.Tirol 0.107108 0.043142 2.483 0.013
L1.Vorarlberg -0.056832 0.037657 -1.509 0.131
L1.Wien 0.031970 0.069433 0.460 0.645
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.044727 0.124344 0.360 0.719
L1.Burgenland -0.033720 0.080770 -0.417 0.676
L1.Kärnten 0.040240 0.042624 0.944 0.345
L1.Niederösterreich -0.181059 0.168684 -1.073 0.283
L1.Oberösterreich 0.433782 0.165413 2.622 0.009
L1.Salzburg 0.285729 0.086206 3.314 0.001
L1.Steiermark 0.107846 0.112822 0.956 0.339
L1.Tirol 0.316764 0.091185 3.474 0.001
L1.Vorarlberg 0.027353 0.079592 0.344 0.731
L1.Wien -0.034259 0.146755 -0.233 0.815
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189298 0.030216 6.265 0.000
L1.Burgenland 0.088871 0.019627 4.528 0.000
L1.Kärnten -0.007576 0.010358 -0.731 0.465
L1.Niederösterreich 0.258584 0.040990 6.308 0.000
L1.Oberösterreich 0.141372 0.040195 3.517 0.000
L1.Salzburg 0.045391 0.020948 2.167 0.030
L1.Steiermark 0.023584 0.027416 0.860 0.390
L1.Tirol 0.089606 0.022158 4.044 0.000
L1.Vorarlberg 0.057939 0.019341 2.996 0.003
L1.Wien 0.114018 0.035661 3.197 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111765 0.030574 3.656 0.000
L1.Burgenland 0.043248 0.019860 2.178 0.029
L1.Kärnten -0.013635 0.010480 -1.301 0.193
L1.Niederösterreich 0.186652 0.041476 4.500 0.000
L1.Oberösterreich 0.309135 0.040672 7.601 0.000
L1.Salzburg 0.104425 0.021196 4.927 0.000
L1.Steiermark 0.108531 0.027741 3.912 0.000
L1.Tirol 0.101493 0.022420 4.527 0.000
L1.Vorarlberg 0.068928 0.019570 3.522 0.000
L1.Wien -0.021498 0.036084 -0.596 0.551
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.123814 0.056077 2.208 0.027
L1.Burgenland -0.047040 0.036426 -1.291 0.197
L1.Kärnten -0.045925 0.019223 -2.389 0.017
L1.Niederösterreich 0.147134 0.076074 1.934 0.053
L1.Oberösterreich 0.148325 0.074599 1.988 0.047
L1.Salzburg 0.282415 0.038878 7.264 0.000
L1.Steiermark 0.053093 0.050881 1.043 0.297
L1.Tirol 0.168393 0.041123 4.095 0.000
L1.Vorarlberg 0.097833 0.035895 2.726 0.006
L1.Wien 0.074381 0.066184 1.124 0.261
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062024 0.044330 1.399 0.162
L1.Burgenland 0.032157 0.028795 1.117 0.264
L1.Kärnten 0.051418 0.015196 3.384 0.001
L1.Niederösterreich 0.207341 0.060138 3.448 0.001
L1.Oberösterreich 0.302198 0.058972 5.124 0.000
L1.Salzburg 0.043550 0.030734 1.417 0.156
L1.Steiermark 0.007656 0.040222 0.190 0.849
L1.Tirol 0.137003 0.032508 4.214 0.000
L1.Vorarlberg 0.074588 0.028376 2.629 0.009
L1.Wien 0.082599 0.052320 1.579 0.114
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170708 0.053163 3.211 0.001
L1.Burgenland 0.000364 0.034533 0.011 0.992
L1.Kärnten -0.064080 0.018224 -3.516 0.000
L1.Niederösterreich -0.089718 0.072121 -1.244 0.213
L1.Oberösterreich 0.198851 0.070722 2.812 0.005
L1.Salzburg 0.055335 0.036857 1.501 0.133
L1.Steiermark 0.241394 0.048237 5.004 0.000
L1.Tirol 0.499323 0.038986 12.808 0.000
L1.Vorarlberg 0.053376 0.034030 1.569 0.117
L1.Wien -0.063182 0.062745 -1.007 0.314
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.154724 0.059900 2.583 0.010
L1.Burgenland -0.007210 0.038909 -0.185 0.853
L1.Kärnten 0.062109 0.020533 3.025 0.002
L1.Niederösterreich 0.193515 0.081260 2.381 0.017
L1.Oberösterreich -0.072038 0.079684 -0.904 0.366
L1.Salzburg 0.208423 0.041528 5.019 0.000
L1.Steiermark 0.135677 0.054349 2.496 0.013
L1.Tirol 0.069280 0.043926 1.577 0.115
L1.Vorarlberg 0.133804 0.038342 3.490 0.000
L1.Wien 0.124127 0.070696 1.756 0.079
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.375193 0.034996 10.721 0.000
L1.Burgenland 0.001743 0.022732 0.077 0.939
L1.Kärnten -0.022549 0.011996 -1.880 0.060
L1.Niederösterreich 0.216484 0.047475 4.560 0.000
L1.Oberösterreich 0.211395 0.046554 4.541 0.000
L1.Salzburg 0.042307 0.024262 1.744 0.081
L1.Steiermark -0.018036 0.031753 -0.568 0.570
L1.Tirol 0.102690 0.025663 4.001 0.000
L1.Vorarlberg 0.064947 0.022401 2.899 0.004
L1.Wien 0.027747 0.041303 0.672 0.502
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037589 0.126778 0.185169 0.148233 0.107713 0.090235 0.047124 0.211673
Kärnten 0.037589 1.000000 -0.017271 0.133396 0.053729 0.092502 0.439144 -0.057143 0.094367
Niederösterreich 0.126778 -0.017271 1.000000 0.331729 0.137259 0.290229 0.081766 0.169337 0.310029
Oberösterreich 0.185169 0.133396 0.331729 1.000000 0.223144 0.315856 0.168354 0.153141 0.259350
Salzburg 0.148233 0.053729 0.137259 0.223144 1.000000 0.134624 0.105506 0.126131 0.134103
Steiermark 0.107713 0.092502 0.290229 0.315856 0.134624 1.000000 0.140750 0.119399 0.064574
Tirol 0.090235 0.439144 0.081766 0.168354 0.105506 0.140750 1.000000 0.092793 0.143888
Vorarlberg 0.047124 -0.057143 0.169337 0.153141 0.126131 0.119399 0.092793 1.000000 0.007480
Wien 0.211673 0.094367 0.310029 0.259350 0.134103 0.064574 0.143888 0.007480 1.000000